package behavior.Observer;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by LYJ on 2016/10/21.
    抽象主题角色
 */
public abstract class Subject {
    private List<Observer> list=new ArrayList<>();
    public void attach(Observer observer){
        list.add(observer);
    }
    public void detach(Observer observer){
        list.remove(observer);
    }
    public void notifyObservers(String str){
        int len=list.size();
        for(int i=0;i<len;i++){
            list.get(i).update(str);
        }
    }
}
